<?php

class ArticleInfo
{
    const MAX_SLUG_LEN = 100;
    
    private $articleId = null;
    private $language = SiteLanguage::EN;
    private $type = ArticleType::PRESS_RELEASE;
    private $title = '';
    private $content = '';
    private $excerpt = '';
    private $categoryId = null;
    private $metaTitle = '';
    private $slug = '';
    private $isPublished = false;
    private $tags = '';
    private $monthlyUniqueViews = 0;
    private $createDate = null;
    private $updateDate = null;
    private $publishDate = null;

    public function SetArticleId( $id )
    {
        $this->articleId = $id;
    }
    
    public function GetArticleId()
    {
        return $this->articleId;
    }

    public function SetLanguage( $language )
    {
        $this->language = $language;
    }

    public function GetLanguage()
    {
        return $this->language;
    }

    public function SetType( $type )
    {
        $this->type = $type;
    }

    public function GetType()
    {
        return $this->type;
    }

    public function SetTitle( $title )
    {
        $this->title = $title;
    }

    public function GetTitle()
    {
        return $this->title;
    }

    public function SetContent( $content )
    {
        $this->content = $content;
    }

    public function GetContent()
    {
        return $this->content;
    }
                        
    public function SetExcerpt( $excerpt )
    {
        $this->excerpt = $excerpt;
    }

    public function GetExcerpt()
    {
        return $this->excerpt;
    }

    public function SetCategoryId( $id )
    {
        $this->categoryId = $id;
    }

    public function GetCategoryId()
    {
        return (int)$this->categoryId;
    }

    public function SetMetaTitle( $metaTitle )
    {
        $this->metaTitle = $metaTitle;
    }

    public function GetMetaTitle()
    {
        return $this->metaTitle;
    }

    public function SetSlug( $slug )
    {
        $this->slug = $slug;
    }

    public function GetSlug()
    {
        return $this->slug;
    }

    public function SetIsPublished( $isPublished )
    {
        $this->isPublished = $isPublished;
    }

    public function GetIsPublished()
    {
        return $this->isPublished;
    }

    public function SetTags( $tags )
    {
        $this->tags = $tags;
    }

    public function GetTags()
    {
        return $this->tags;
    }

    public function SetMonthlyUniqueViews( $monthlyUniqueViews )
    {
        $this->monthlyUniqueViews = $monthlyUniqueViews;
    }

    public function GetMonthlyUniqueViews()
    {
        return (int)$this->monthlyUniqueViews;
    }

    public function SetCreateDate( $createDate )
    {
        if ( !is_numeric($createDate) )
        {
            $createDate = strtotime($createDate);
        }
        $this->createDate = $createDate;
    }

    public function GetCreateDate()
    {
        return $this->createDate;
    }

    public function SetUpdateDate( $updateDate = null )
    {
        if ( $updateDate !== null && !is_numeric($updateDate) )
        {
            $updateDate = strtotime($updateDate);
        }
        $this->updateDate = $updateDate;
    }

    public function GetUpdateDate()
    {
        return $this->updateDate;
    }

    public function SetPublishDate( $publishDate = null )
    {
        if ( $publishDate !== null && !is_numeric($publishDate) )
        {
            $publishDate = strtotime($publishDate);
        }
        $this->publishDate = $publishDate;
    }

    public function GetPublishDate()
    {
        return $this->publishDate;
    }

    public function GetTitleSlug()
    {
        return StringUtils::Slugify($this->title);
    }

    public function GenerateSlug()
    {
       $slug =  $this->GetTitleSlug();
       
        // truncate long text
        if ( strlen($slug) > self::MAX_SLUG_LEN )
        {
            $slug = substr($slug, 0, self::MAX_SLUG_LEN);
            $pos = strrpos($slug, '-');
            if ($pos > 0)
            {
                $slug = substr($slug, 0, $pos);
            }
        }

        return $slug;
    }

    public function GetUrl($product = '')
    {
        $url = '';

        if ($this->type == ArticleType::PRESS_RELEASE)
        {
            $url = '/company/press-releases/';
        }

        $url .= $this->GetSlug() . '.html';

        return $url;
    }
}

?>
